// pages/rentPet/rentPet.js
Page({

  /**
   * 页面的初始数据
   */
  data: {
  petImage: '', 
  },

  submitForm(e) {
    const formData = {
      petName: e.detail.value.petName,
      petAge: e.detail.value.petAge,
      petGender: e.detail.value.petGender,
      petDescription: e.detail.value.petDescription,
      petPrice: e.detail.value.petPrice,
    };

    // You can now send the formData to your backend API
    // Example:
    wx.uploadFile({
      url: 'http://localhost:8080/pet/upload',
      filePath: this.data.petImage,
      name: 'file',
      formData: {
          'pet': JSON.stringify({
              // your pet data here
          })
      },
      header: {
          'Content-Type': 'multipart/form-data',
      },
      success: (res) => {
        console.log('Pet published successfully:', res);
        // Handle success, e.g., show a success message or navigate to another page
        wx.showToast({
          title: 'Pet published successfully',
          icon: 'success',
          duration: 2000,
          success: () => {
            wx.switchTab({
              url: '/pages/home/home',
            });
          },
        });
      },
      fail: (error) => {
        console.error('Error publishing pet:', error);
        // Handle error, e.g., show an error message
        wx.showToast({
          title: 'Error publishing pet',
          icon: 'none',
          duration: 2000,
        });
      },
    });
  },

  chooseImage() {
    wx.chooseImage({
      count: 1,
      success: (res) => {
        const tempFilePath = res.tempFilePaths[0];
        console.log(tempFilePath);
        this.setData({
          petImage: tempFilePath,
        });
      },
    });
  },

  
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {

  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage() {

  }
})